package arithmetic;

import java.util.Arrays;

public class QuickSortTest {

    public static void main(String[] args) {
        QuickSortTest quickSortTest = new QuickSortTest();
        int [] array = new int [] {3,7,10,17,9,6,2};
        quickSortTest.sort(array,0,array.length-1);
        System.out.println(Arrays.toString(array));
    }

    private void sort(int[] array, int left, int right) {
        int [] partitionArray = patition(array,left,right);
        sort(partitionArray,0,left-1);
        sort(partitionArray,left+1, right);

    }

    private int[] patition(int[] array, int left, int right) {
        if(left > right){
            return null;
        }
        //定义基数
        int pivot = array[left];
        int i = left;
        int j = right;
        while (i < j) {

            while (array[j] > pivot &&  i < j){
                j--;
            }

            array[i] = array[j];

            while (array[i] < pivot && i < j){
                i++;
            }
            array[j] = array[i];

        }
        array[i] = pivot;
        return array;
    }
}
